import { Module, DynamicModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SystemsModule } from './systems/systems.module';
import { ConfigModule } from './config/config.module';
import { ConfigService } from './config/config.service';
import { Users } from './systems/users/users.entity';
import { LogService } from './systems/log/log.service'
import { Log } from './systems/log/log.entity'
const Orm = (): DynamicModule => {
  let env = process.env.NODE_ENV;
  if (env !== 'production') {
    env = 'development';
  }
  const config = new ConfigService(`./env/${env}.env`);
  return TypeOrmModule.forRoot({
    type: "mariadb",
    // type: 'mysql',
    host: config.databaseHost,
    port: config.databasePort,
    username: config.databaseUserName,
    password: config.databasePassword,
    database: config.databaseName,
    entities: [__dirname + '/systems/**/*.entity{.ts,.js}'],
    subscribers: [__dirname + '/systems/**/*.entity{.ts,.js}'],
    synchronize: config.databaseSynchronize,
    dropSchema: config.databaseDropSchema,
  });
};

@Module({
  imports: [
    SystemsModule,
    ConfigModule,
    Orm(),
    TypeOrmModule.forFeature([Users,Log]),

  ],
  controllers: [AppController],
  providers: [AppService,LogService],
})
export class AppModule { }
